home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 1.0 beta / flock-1.0RC3.en-US.win32.exe / flock / components / flockFlockChannel.js < prev    next >
Text File  |  2007-10-18  |  6KB  |  204 lines

  1. //
  2. // BEGIN FLOCK GPL
  3. // 
  4. // Copyright Flock Inc. 2005-2007
  5. // http://flock.com
  6. // 
  7. // This file may be used under the terms of of the
  8. // GNU General Public License Version 2 or later (the "GPL"),
  9. // http://www.gnu.org/licenses/gpl.html
  10. // 
  11. // Software distributed under the License is distributed on an "AS IS" basis,
  12. // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. // for the specific language governing rights and limitations under the
  14. // License.
  15. // 
  16. // END FLOCK GPL
  17. //
  18.  
  19. const CLASS_ID                = Components.ID("{61D8E631-FE24-499A-906C-6937D939EA71}");
  20. const CLASS_NAME              = "Flock Protocol Channel";
  21. const CONTRACT_ID             = "@flock.com/flock-channel;1";
  22.  
  23. const LOAD_NORMAL =                Components.interfaces.nsIRequest.LOAD_NORMAL;
  24. const LOAD_BACKGROUND =            Components.interfaces.nsIRequest.LOAD_BACKGROUND;
  25. const INHIBIT_CACHING =            Components.interfaces.nsIRequest.INHIBIT_CACHING;
  26. const INHIBIT_PERSISTENT_CACHING = Components.interfaces.nsIRequest.INHIBIT_PERSISTENT_CACHING;
  27. const LOAD_BYPASS_CACHE =          Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
  28. const LOAD_FROM_CACHE =            Components.interfaces.nsIRequest.LOAD_FROM_CACHE;
  29. const VALIDATE_ALWAYS =            Components.interfaces.nsIRequest.VALIDATE_ALWAYS;
  30. const VALIDATE_NEVER =             Components.interfaces.nsIRequest.VALIDATE_NEVER;
  31. const VALIDATE_ONCE_PER_SESSION =  Components.interfaces.nsIRequest.VALIDATE_ONCE_PER_SESSION;
  32.  
  33. function flockFlockChannel()
  34. {
  35.   debug("flockFlockChannel: starting up...\n");
  36. }
  37.  
  38. flockFlockChannel.prototype = {
  39.  
  40.   contentCharset: "utf-8",
  41.   contentLength: -1,
  42.   contentType: "text/html",
  43.   loadAttributes: null,
  44.   loadGroup: null,
  45.   notificationCallbacks: null,
  46.   owner: null,
  47.   securityInfo: null,
  48.   shouldCache: false,
  49.   bypassCache: false,
  50.   loadFlags: null,
  51.   
  52.   init: function(AURI)
  53.   {
  54.     this.URI = AURI;
  55.     this.originalURI = AURI;
  56.     this._pending = true;
  57.   },
  58.   
  59.   asyncOpen: function(listener, context)
  60.   {
  61.     this.listener = listener;
  62.     this.context  = context;
  63.  
  64.     if (this.loadFlags & LOAD_BYPASS_CACHE || this.loadFlags & VALIDATE_ALWAYS) {
  65.       // They pressed reload or shift+reload.
  66.       this.bypassCache = true;
  67.     } else {
  68.       this.bypassCache = false;
  69.     }
  70.     if (this.loadFlags & INHIBIT_CACHING || this.loadFlags & INHIBIT_PERSISTENT_CACHING) {
  71.       // For privacy reasons we shouldn't cache this (eg it is HTTPS).
  72.       // XXX we do not currently honor this.
  73.       this.shouldCache = false;
  74.     } else {
  75.       this.shouldCache = true;
  76.     }
  77.  
  78.     if (this.loadGroup) {
  79.       this.loadGroup.addRequest(this, null);
  80.     }
  81.   },
  82.  
  83.   open: function()
  84.   {
  85.     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  86.   },
  87.   
  88.   // nsIRequest
  89.   isPending: function()
  90.   {
  91.     return this._pending;
  92.   },
  93.  
  94.   // nsIRequest
  95.   status: Components.results.NS_OK,
  96.  
  97.   // nsIRequest
  98.   cancel: function(status)
  99.   {
  100.     if (this._pending) {
  101.       this._pending = false;
  102.       this.listener.onStopRequest(this, this.context, status);
  103.       if (this.loadGroup) {
  104.         this.loadGroup.removeRequest(this, null, status);
  105.       }
  106.     }
  107.     this.status = status;
  108.   },
  109.  
  110.   // nsIRequest
  111.   suspend: function()
  112.   {
  113.     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  114.   },
  115.   
  116.   // nsIRequest
  117.   resume: function()
  118.   {
  119.     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  120.   },
  121.  
  122.   // nsIClassInfo
  123.   getInterfaces: function(aCount)
  124.   {
  125.     var interfaces = [Components.interfaces.nsIChannel, Components.interfaces.flockIFlockChannel, Components.interfaces.nsIRequest, Components.interfaces.nsIClassInfo];
  126.     aCount.value = interfaces.length;
  127.     return interfaces;
  128.   },
  129.  
  130.   // nsIClassInfo
  131.   getHelperForLanguage: function(aLanguage)
  132.   {
  133.     return null;
  134.   },
  135.  
  136.   // nsIClassInfo
  137.   contractID: CONTRACT_ID,
  138.  
  139.   // nsIClassInfo
  140.   classDescription: CLASS_NAME,
  141.  
  142.   // nsIClassInfo
  143.   classID: CLASS_ID,
  144.  
  145.   // nsIClassInfo
  146.   implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
  147.  
  148.   // nsIClassInfo
  149.   flags: null,
  150.   
  151.   // nsISupports
  152.   QueryInterface: function(aIID)
  153.   {
  154.     if (!aIID.equals(Components.interfaces.nsISupports) && !aIID.equals(Components.interfaces.flockIFlockChannel) && !aIID.equals(Components.interfaces.nsIChannel) && !aIID.equals(Components.interfaces.nsIRequest) && !aIID.equals(Components.interfaces.nsIClassInfo))
  155.       throw Components.results.NS_ERROR_NO_INTERFACE;
  156.     return this;
  157.   }
  158.  
  159. };
  160.  
  161. /******************************************************************************
  162.  * XPCOM Functions for construction and registration
  163.  ******************************************************************************/
  164. var Module = {
  165.   _firstTime: true,
  166.   registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
  167.   {
  168.     if (this._firstTime) {
  169.       this._firstTime = false;
  170.       throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  171.     }
  172.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  173.     aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
  174.   },
  175.  
  176.   unregisterSelf: function(aCompMgr, aLocation, aType)
  177.   {
  178.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  179.     aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);        
  180.   },
  181.   
  182.   getClassObject: function(aCompMgr, aCID, aIID)
  183.   {
  184.     if (!aIID.equals(Components.interfaces.nsIFactory))
  185.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  186.     if (aCID.equals(CLASS_ID))
  187.       return Factory;
  188.     throw Components.results.NS_ERROR_NO_INTERFACE;
  189.   },
  190.  
  191.   canUnload: function(aCompMgr) { return true; }
  192. };
  193.  
  194. var Factory = {
  195.   createInstance: function(aOuter, aIID)
  196.   {
  197.     if (aOuter != null)
  198.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  199.     return (new flockFlockChannel()).QueryInterface(aIID);
  200.   }
  201. };
  202.  
  203. function NSGetModule(aCompMgr, aFileSpec) { return Module; }
  204.